package com.member.web.controller.shop;

import com.baomidou.mybatisplus.core.conditions.query.LambdaQueryWrapper;
import com.member.common.annotation.Log;
import com.member.common.core.controller.BaseController;
import com.member.common.core.domain.AjaxResult;
import com.member.common.core.domain.model.LoginUser;
import com.member.common.core.page.TableDataInfo;
import com.member.common.enums.BusinessType;
import com.member.common.utils.poi.ExcelUtil;
import com.member.shop.domain.SysBizFeedback;
import com.member.shop.service.ISysBizFeedbackService;
import org.springframework.security.access.prepost.PreAuthorize;
import org.springframework.web.bind.annotation.*;

import javax.annotation.Resource;
import javax.servlet.http.HttpServletResponse;
import java.time.LocalDateTime;
import java.util.Date;
import java.util.List;

/**
 * 意见反馈Controller
 *
 * @author thomas
 * @date 2024-11-09
 */
@RestController
@RequestMapping("/shop/other/feedback")
public class SysBizFeedbackController extends BaseController {
    @Resource
    private ISysBizFeedbackService sysBizFeedbackService;

    /**
     * 查询意见反馈列表
     */
    @PreAuthorize("@ss.hasPermi('other:feedback:list')")
    @GetMapping("/list")
    public TableDataInfo list(SysBizFeedback sysBizFeedback) {
        startPage();
        setTenantId(sysBizFeedback);
        List<SysBizFeedback> list = sysBizFeedbackService.selectSysBizFeedbackList(sysBizFeedback);
        return getDataTable(list);
    }

    private void setTenantId(SysBizFeedback sysBizFeedback) {
        LoginUser loginUser = getLoginUser();
        Long tenantId = loginUser.getTenantId();
        if (tenantId != null && tenantId > 0) {
            sysBizFeedback.setTenantId(tenantId);
        }
    }

    /**
     * 导出意见反馈列表
     */
    @PreAuthorize("@ss.hasPermi('other:feedback:export')")
    @Log(title = "意见反馈", businessType = BusinessType.EXPORT)
    @PostMapping("/export")
    public void export(HttpServletResponse response, SysBizFeedback sysBizFeedback) {
        setTenantId(sysBizFeedback);
        List<SysBizFeedback> list = sysBizFeedbackService.selectSysBizFeedbackList(sysBizFeedback);
        ExcelUtil<SysBizFeedback> util = new ExcelUtil<SysBizFeedback>(SysBizFeedback.class);
        util.exportExcel(response, list, "意见反馈数据");
    }

    /**
     * 获取意见反馈详细信息
     */
    @PreAuthorize("@ss.hasPermi('other:feedback:query')")
    @GetMapping(value = "/{id}")
    public AjaxResult getInfo(@PathVariable("id") Long id) {
        return success(sysBizFeedbackService.selectSysBizFeedbackById(id));
    }

    /**
     * 新增意见反馈
     */
    @PreAuthorize("@ss.hasPermi('other:feedback:add')")
    @Log(title = "意见反馈", businessType = BusinessType.INSERT)
    @PostMapping
    public AjaxResult add(@RequestBody SysBizFeedback sysBizFeedback) {
        setTenantId(sysBizFeedback);
        sysBizFeedback.setUpdateTime(new Date());
        return toAjax(sysBizFeedbackService.insertSysBizFeedback(sysBizFeedback));
    }

    /**
     * 修改意见反馈
     */
    @PreAuthorize("@ss.hasPermi('other:feedback:edit')")
    @Log(title = "意见反馈", businessType = BusinessType.UPDATE)
    @PutMapping
    public AjaxResult edit(@RequestBody SysBizFeedback sysBizFeedback) {
        setTenantId(sysBizFeedback);
        sysBizFeedback.setDealTime(LocalDateTime.now());
        return toAjax(sysBizFeedbackService.updateSysBizFeedback(sysBizFeedback));
    }

    /**
     * 删除意见反馈
     */
    @PreAuthorize("@ss.hasPermi('other:feedback:remove')")
    @Log(title = "意见反馈", businessType = BusinessType.DELETE)
    @DeleteMapping("/{ids}")
    public AjaxResult remove(@PathVariable Long[] ids) {
        return toAjax(sysBizFeedbackService.deleteSysBizFeedbackByIds(ids));
    }
}
